<?php


namespace app\api\controller;


use addons\shopro\model\Goods;
use app\api\model\Complaints;
use app\api\model\ComplaintsCategory;
use app\api\model\ExpertCategory;
use app\api\model\Project;
use app\api\model\Registered;
use app\common\controller\Api;
use think\Validate;

/**
 * 专家接口
 */
class Expert extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    /**
     * 专家列表
     *
     * @ApiTitle    (专家列表)
     * @ApiSummary  (专家列表)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=category_id, type=string, required=true, description="分类id，默认为空，空=全部")
     * @ApiHeaders  (name=page, type=string, required=true, description="页码，默认为1")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function index()
    {
        $category_id=$this->request->request('category_id','');
        $page=$this->request->request('page',1);
        $res=\app\api\model\Expert::where('status',1);
        if (!empty($category_id)) $res=$res->where('expert_category_id',$category_id);
        $res=$res->page($page,10)->select();
        $this->success('成功',$res);
    }


    /**
     * 专家分类
     *
     * @ApiTitle    (专家分类)
     * @ApiSummary  (专家分类)
     * @ApiMethod   (POST)
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function cagegoryList()
    {
        $res=ExpertCategory::where('status',1)->select();
        $this->success('成功',$res);
    }

    /**
     * 专家详情
     *
     * @ApiTitle    (专家详情)
     * @ApiSummary  (专家详情)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=id, type=string, required=true, description="专家id")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function detail()
    {
        $id=$this->request->request('id','');
        if (empty($id)) $this->error('请传入专家id');
        $info=\app\api\model\Expert::where('status',1)->where('id',$id)->find();
        $this->success('成功',$info);
    }

    /**
     * 专家项目列表
     *
     * @ApiTitle    (专家项目列表)
     * @ApiSummary  (专家项目列表)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=id, type=string, required=true, description="专家id")
     * @ApiHeaders  (name=page, type=string, required=true, description="页码，默认为1")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function expertGoodsList()
    {
        $id=$this->request->request('id','');
        $page=$this->request->request('page',1);
        if (empty($id)) $this->error('请传入专家id');
        $list=Goods::where('expert_id',$id)->where('status','up')->page($page,10)->select();
        $this->success('成功',$list);
    }

    /**
     * 所有专家列表
     *
     * @ApiTitle    (所有专家列表)
     * @ApiSummary  (所有专家列表)
     * @ApiMethod   (POST)
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function expertAll()
    {
        $res=\app\api\model\Expert::where('status',1)->field('id,name')->select();
        $this->success('成功',$res);
    }

    /**
     * 预约项目列表
     *
     * @ApiTitle    (预约项目列表)
     * @ApiSummary  (预约项目列表)
     * @ApiMethod   (POST)
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function projectList()
    {
        $res=Project::where('status',1)->field('id,name')->select();
        $this->success('成功',$res);
    }

    /**
     * 在线挂号提交
     *
     * @ApiTitle    (在线挂号提交)
     * @ApiSummary  (在线挂号提交)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=name, type=string, required=true, description="姓名")
     * @ApiHeaders  (name=mobile, type=string, required=true, description="手机号")
     * @ApiHeaders  (name=yuyue, type=string, required=true, description="来院时间")
     * @ApiHeaders  (name=doctor, type=string, required=true, description="预约医生名称")
     * @ApiHeaders  (name=project, type=string, required=true, description="预约项目名称")
     * @ApiHeaders  (name=desc, type=string, required=true, description="需求简述")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function registeredSubmit()
    {
        $name=$this->request->request('name','');
        $mobile=$this->request->request('mobile','');
        $yuyue=$this->request->request('yuyue','');
        $doctor=$this->request->request('doctor','');
        $project=$this->request->request('project','');
        $desc=$this->request->request('desc','');
        if (empty($name)) $this->error('请输入预约姓名');
        if (empty($mobile)) $this->error('请输入预约电话');
        if (!Validate::regex($mobile, "^1\d{10}$")) {
            $this->error('手机号格式不正确');
        }
        if (empty($yuyue)||$yuyue=='请选择来院时间') $this->error('请选择来院时间');
        if (empty($doctor)||$doctor=='请选择医生') $this->error('请选择预约医生');
        if (empty($project)||$project=='请选择项目') $this->error('请选择预约项目');
        if (empty($desc)) $this->error('请输入需求简述');
//        if (empty($money)) $this->error('请输入挂号费');
        $data['name']=$name;
        $data['mobile']=$mobile;
        $data['yuyue']=$yuyue;
        $data['doctor']=$doctor;
        $data['project']=$project;
        $data['desc']=$desc;
        $data['createtime']=time();
        $res=Registered::create($data);
        if ($res) $this->success('挂号成功');
        else $this->error('挂号失败');
    }

    /**
     * 投诉类型列表
     *
     * @ApiTitle    (投诉类型列表)
     * @ApiSummary  (投诉类型列表)
     * @ApiMethod   (POST)
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function complaintsCategoryList()
    {
        $res=ComplaintsCategory::where('status',1)->field('id,name')->select();
        $this->success('成功',$res);
    }

    /**
     * 在线投诉提交
     *
     * @ApiTitle    (在线投诉提交)
     * @ApiSummary  (在线投诉提交)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=name, type=string, required=true, description="投诉类型名称")
     * @ApiHeaders  (name=desc, type=string, required=true, description="描述")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function complaintsSumit()
    {
        $name=$this->request->request('name','');
        $desc=$this->request->request('desc','');
        if (empty($desc)) $this->error('请输入问题描述');
        $data['name']=$name;
        $data['desc']=$desc;
        $res=Complaints::create($data);
        if ($res) $this->success('成功');
        else $this->error('失败');
    }

    /**
     * 医院信息
     *
     * @ApiTitle    (医院信息)
     * @ApiSummary  (医院信息)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=name, type=string, required=true, description="投诉类型名称")
     * @ApiHeaders  (name=desc, type=string, required=true, description="描述")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    })
     */
    public function hospitalInfo()
    {
        $hot_mobile=config('site.hospital_hot_mobile');
        $gu_mobile=config('site.hospital_gu_mobile');
        $hospital_address=config('site.hospital_address');
        $hospital_longitude=config('site.hospital_longitude');
        $hospital_latitude=config('site.hospital_latitude');
        $hospital_desc=config('site.hospital_desc');
        $this->success('成功',compact('hospital_address','hot_mobile','gu_mobile',
        'hospital_desc','hospital_longitude','hospital_latitude'));

    }

}